package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sc.nft.entity.vo.LotteryRecordListVO;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.ActivityRecord;
import com.sc.nft.mapper.ActivityRecordMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * (sc_activity_record)数据DAO
 *
 * @author Sun
 * @since 2022-07-08 13:20:49
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class ActivityRecordDao extends ServiceImpl<ActivityRecordMapper, ActivityRecord> {

    public List<ActivityRecord> getListByUserId(Long userId) {
        LambdaQueryWrapper<ActivityRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ActivityRecord::getUserId,userId);
        wrapper.last("order by id desc");
        return list(wrapper);
    }

    public List<LotteryRecordListVO> getLotteryRecordList() {
        return baseMapper.getLotteryRecordList();
    }

    public Integer getCountByUserIdAndActivityId(Long userId, Long activityId) {
        LambdaQueryWrapper<ActivityRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ActivityRecord::getUserId,userId);
        wrapper.eq(ActivityRecord::getActivityId,activityId);
        return count(wrapper);
    }
}